/*
   MSRControl.cpp
   
   Copyright (C) 2006 LinuxOne, Inc. <Republic of korea>

   This library is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as
   published by the Free Software Foundation; either version 2.1
   of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   Lessor General Public License for more details.

   You should have received a copy of the GNU Lessor General Public
   License along with this library; if not, write to the Free Software
   Foundation, inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

   Hyunjin Kim <mgc521@linuxone.co.kr>

   LinuxOne, Inc., hereby disclaims all copylight
   written by Hyunjin Kim, 20 December 2006
*/

#include <control/MSRControl.h>

namespace booyopos
{

CMSR::CMSR()
{
	deviceControlDescription = "BooyoPOS MSR Device Control";
	deviceControlVersion = 0;

	cms= new services::CMSRService;

	CBaseControl::bs=dynamic_cast<services::CBaseService *>(cms);
}

CMSR::~CMSR()
{
}

/* Capabilities */
bool
CMSR::GetCapISO()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->capISO;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

bool
CMSR::GetCapJISOne()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->capJISOne;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

bool
CMSR::GetCapJISTwo()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->capJISTwo;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

int
CMSR::GetCapPowerReporting()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->capPowerReporting;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

bool
CMSR::GetCapTransmitSentinels()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->capTransmitSentinels;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

bool
CMSR::GetCapStatisticsReporting()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->capStatisticsReporting;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

bool
CMSR::GetCapUpdateStatistics()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->capUpdateStatistics;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

bool
CMSR::GetCapCompareFirmwareVersion()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->capCompareFirmwareVersion;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

bool
CMSR::GetCapUpdateFirmware()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->capUpdateFirmware;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

int
CMSR::GetCapWritableTracks()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->capWritableTracks;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

/* Properties */
std::string
CMSR::GetAccountNumber()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->accountNumber;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

bool
CMSR::GetAutoDisable()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->autoDisable;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CMSR::SetAutoDisable(bool autoDisable)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		cms->SetAutoDisable(autoDisable);
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

int
CMSR::GetDataCount()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->dataCount;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

bool
CMSR::GetDataEventEnabled()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->dataEventEnabled;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CMSR::SetDataEventEnabled(bool dataEventEnabled)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		cms->SetDataEventEnabled(dataEventEnabled);
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

bool
CMSR::GetDecodeData()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->decodeData;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CMSR::SetDecodeData(bool decodeData)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		cms->SetDecodeData(decodeData);
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

int
CMSR::GetErrorReportingType()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->errorReportingType;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CMSR::SetErrorReportingType(int errorReportingType)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		cms->SetErrorReportingType(errorReportingType);
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

std::string
CMSR::GetExpirationDate()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->expirationDate;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

std::string
CMSR::GetFirstName()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->firstName;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

std::string
CMSR::GetMiddleInitial()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->middleInitial;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

bool
CMSR::GetParseDecodeData()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->parseDecodeData;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CMSR::SetParseDecodeData(bool parseDecodeData)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		cms->SetParseDecodeData(parseDecodeData);
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

std::string
CMSR::GetServiceCode()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->serviceCode;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

std::string
CMSR::GetSuffix()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->suffix;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

std::string
CMSR::GetSurname()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->surname;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

std::string
CMSR::GetTitle()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->title;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

char*
CMSR::GetTrack1Data()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->track1Data;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

char*
CMSR::GetTrack1DiscretionaryData()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->track1DiscretionaryData;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

char*
CMSR::GetTrack2Data()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->track2Data;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

char*
CMSR::GetTrack2DiscretionaryData()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->track2DiscretionaryData;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

char*
CMSR::GetTrack3Data()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->track3Data;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

int
CMSR::GetTracksToRead()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->tracksToRead;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CMSR::SetTracksToRead(int tracksToRead)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		cms->SetTracksToRead(tracksToRead);
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

int
CMSR::GetPowerNotify()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->powerNotice;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CMSR::SetPowerNotify(int powerNotice)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		cms->SetPowerNotify(powerNotice);
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

int
CMSR::GetPowerState()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->powerState;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

char*
CMSR::GetTrack4Data()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->track4Data;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

bool
CMSR::GetTransmitSentinels()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->transmitSentinels;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CMSR::SetTransmitSentinels(bool transmitSentinels)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		cms->SetTransmitSentinels(transmitSentinels);
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

int
CMSR::GetEncodingMaxLength()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->encodingMaxLength;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

int
CMSR::GetTracksToWrite()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return cms->tracksToWrite;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CMSR::SetTracksToWrite(int tracksToWrite)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		cms->SetTracksToWrite(tracksToWrite);
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

/* Methods */
void
CMSR::WriteTracks(std::string data, int timeout)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		cms->WriteTracks(data, timeout);
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

/* Statistics */
void
CMSR::ClearInput()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		cms->ClearInput();
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CMSR::ResetStatistics(std::string statisticsBuffer)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		cms->ResetStatistics(statisticsBuffer);
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CMSR::RetrieveStatistics(std::string statisticsBuffer[])
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		cms->RetrieveStatistics(statisticsBuffer);
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CMSR::UpdateStatistics(std::string statisticsBuffer)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		cms->UpdateStatistics(statisticsBuffer);
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CMSR::CompareFirmwareVersion(std::string firmwareFileName, int* result)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		cms->CompareFirmwareVersion(firmwareFileName, result);
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CMSR::UpdateFirmware(std::string firmwareFileName)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		cms->UpdateStatistics(firmwareFileName);
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CMSR::ClearInputProperties()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		cms->ClearInputProperties();
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

} // namespace booyopos
